
export default {
    state: {
        token: ''||localStorage.getItem('token'),
        userInfo: {}||JSON.parse(localStorage.getItem('userInfo')),
    },
    mutations: {
        SET_TOKEN(state, token) {
            state.token = token
        },
        SET_USERINFO(state, userInfo) {
            state.userInfo = userInfo
        }
    },
    actions: {
        setToken({ commit }, token) {
            commit('SET_TOKEN', token)
        },
        setUserInfo({ commit }, userInfo) {
            commit('SET_USERINFO', userInfo)
        }
    },
    getters: {
        getToken: (state) => state.token,
        isAuthenticated: (state) => !!state.token,
        getUserInfo: (state) => state.userInfo,
    }
}